package com.njwb.day08;


public class TestArguments {
    public static void main(String[] args) {
        System.out.println(sum(1,2));
        System.out.println(sum(1,2,3));
        System.out.println(sum(new int[]{1,2,3,4,5,6,7,8}));

        System.out.println(sum2(1));
        System.out.println(sum2(1,2));
        System.out.println(sum2(1,2,3));
        System.out.println(sum2(new int[]{1,2,3,4,5,6,7,8}));

        fn1(10,2,3,4,5,6,7,8,9);

    }
    //可变长参数放在形参位置最后
    public static void fn1(int i,int... is){
        System.out.println(i);
        System.out.println(is.length);

    }

    //可变长参数
    public static int sum2(int... arr){
        int result=0;
        for (int i=0;i< arr.length;i++){
            result+=arr[i];
        }
        return result;
    }



    public static int sum(int a,int b){
        return a+b;
    }

    public static int sum(int a,int b,int c){
        return a+b+c;
    }

    public static int sum(int[] arr){
        int result=0;
        for (int i=0;i< arr.length;i++){
            result+=arr[i];
        }
        return result;
    }
}
